package com.wc.AlgoOJ_train.train5_数据结构.c7_单调栈与单调队列.覆盖;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/26 21:41
 * @description http://43.138.190.70:8888/p/DS0606
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[] a = new int[N];
    static int[] qMax = new int[N];
    static int[] qMin = new int[N];
    static int hh1, tt1, hh2, tt2;
    static int n, h, top;

    public static void main(String[] args) {
        n = sc.nextInt();
        h = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
        }
        // 二分区间,检查是否有这么大的区间存在
        int l = 1, r = n;
        while (l < r) {
            int mid = l + r + 1 >> 1;
            if (check(mid)) l = mid;
            else r = mid - 1;
        }
        out.println(r);
        out.flush();
    }

    static boolean check(int mid) {
        hh1 = hh2 = 0;
        tt1 = tt2 = -1;
        for (int i = 1; i < mid; i++) {
            while (hh1 <= tt1 && a[i] >= a[qMax[tt1]]) tt1--;
            while (hh2 <= tt2 && a[i] <= a[qMin[tt2]]) tt2--;
            qMax[++tt1] = i;
            qMin[++tt2] = i;
        }
        for (int i = mid; i <= n; i++) {
            while (hh1 <= tt1 && a[i] >= a[qMax[tt1]]) tt1--;
            while (hh2 <= tt2 && a[i] <= a[qMin[tt2]]) tt2--;
            qMax[++tt1] = i;
            qMin[++tt2] = i;
            if (a[qMax[hh1]] - a[qMin[hh2]] < h) return true;
            if (i - mid + 1 == qMax[hh1]) hh1++;
            if (i - mid + 1 == qMin[hh2]) hh2++;
        }
        return false;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
